import { defineComponent, ref } from "vue";
import storage from "@/utils/storage";
import "../style/pubTablecss.scss";

export default defineComponent({
	props: {
		tableData: Object, // 确保类型匹配
		uploadUrl: String,
	},
	emits:["handleBeforeUpload", "handleAvatarSuccess", "handleFixedDialog", "handleShowedDialog"],
	setup(props, context) {
		let beforeAvatarUpload = (rawFile) => {
			// 处理成功上传的逻辑
			context.emit("handleBeforeUpload", rawFile);
		};
		let handleAvatarSuccess = (response, uploadFile) => {
			context.emit("handleAvatarSuccess", response);
		};
		let showFixedDialog = () => {
			context.emit("handleFixedDialog");
		};
		let showShowedDialog = () => {
			context.emit("handleShowedDialog");
		};
		return () => (
			<>
				{props.tableData.handleBtns.map((item) => {
					// 导入
					if (item.import) {
						let token = {
							Authorization: storage.LStorage.get("token"),
						};
						return (
							<el-upload action={props.uploadUrl} show-file-list={false} accept=".xls,.xlsx" class="fUpload" before-upload={beforeAvatarUpload} on-success={handleAvatarSuccess} headers={token}>
								<button class="fBtn blank">{item.text}</button>
							</el-upload>
						);
					} else if (item.downLoad) {
						// 模板下载
						return (
							<span style="margin-left:18px" onClick={item.onClick}>
								{item.text}
							</span>
						);
					} else if (item.fixed) {
						return (
							<el-button onClick={showFixedDialog} class="fBtn blank" type={item.type || "primary"}>
								{item.text || "冻结"}
							</el-button>
						);
					} else if (item.showCol) {
						return (
							<el-button onClick={showShowedDialog} class="fBtn blank" type={item.type || "primary"}>
								{item.text || "展示"}
							</el-button>
						);
					} else {
						return (
							<el-button onClick={item.onClick} class="fBtn blank" type={item.type || "primary"}>
								{item.text}
							</el-button>
						);
					}
				})}
			</>
		);
	},
});
